package modular.mapreduce;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.log4j.BasicConfigurator;

/**
 * windows本地运行
 *
 * @Author yuelinbo
 * @Date 2018/12/12 11:24
 **/
public class JobSubmitLocal {

    public static void main(String[] args) throws Exception{
        BasicConfigurator.configure();


        Configuration conf = new Configuration();
        //指定默认文件系统
        conf.set("fs.defaultFS","file:///");
        //界定mapreduce-job 提交到哪
        conf.set("mapreduce.framework.name","local");

        Job job = Job.getInstance(conf);
        job.setJarByClass(JobSubmitter2.class);

        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReduce.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        FileInputFormat.setInputPaths(job,new Path("f://yue/input/test.txt"));
        FileOutputFormat.setOutputPath(job,new Path("f://yue/output"));

        job.setNumReduceTasks(3);
        boolean b = job.waitForCompletion(true);
        System.exit(b?0:1);
    }
}
